package com.ruoyi.device.util;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.RedisConstans;
import com.ruoyi.device.domain.resp.hatdevice.HatDeviceResp;
import com.ruoyi.device.service.HatDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class UpdateRedisUtils {

    @Autowired
    private HatDeviceService hatDeviceService;

    @Autowired
    private RedisTemplate redisTemplate;
    public void updateBingDevice(){
        List<HatDeviceResp> list = this.hatDeviceService.searchByOrgCode(Constants.CQ_CODE);
        List<HatDeviceResp> respList = list.stream().filter(p -> {
            return p.getElectricFenceResp() != null;
        }).collect(Collectors.toList());
        for (HatDeviceResp deviceResp : respList) {
            this.redisTemplate.opsForHash().put(RedisConstans.BIND_FENCE,deviceResp.getDeviceCode()+deviceResp.getElectricFenceResp().getUserName()+deviceResp.getElectricFenceResp().getId(),deviceResp);
        }
    }
}
